/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package desarrollosoft.ghce.entidades;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 *
 * @author ariel
 */
@Entity
@Table(name = "RESULTADOS_COMPONENTES")
public class ResultadoComponente implements Serializable {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(name = "valor", nullable = true)
    private Double valor;
    
    @ManyToOne
    @JoinColumn(name = "componente_id", nullable = false)
    private Componente componente;
    
    @ManyToOne
    private EstudioLaboratorio estudioLaboratorio;
    
    public ResultadoComponente() {}

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Double getValor() {
        return valor;
    }

    public void setValor(Double valor) {
        this.valor = valor;
    }

    public Componente getComponente() {
        return componente;
    }

    public void setComponente(Componente componente) {
        this.componente = componente;
    }

    public EstudioLaboratorio getEstudioLaboratorio() {
        return estudioLaboratorio;
    }

    public void setEstudioLaboratorio(EstudioLaboratorio estudioLaboratorio) {
        this.estudioLaboratorio = estudioLaboratorio;
    }

    public String getEstilo() {
        if (getComponente() != null) {
            ValorNormal valorNormal = getComponente().getValorNormalElegido();
            if (valor != null && valorNormal != null) {
                Double minimo = valorNormal.getValorMinimo();
                Double maximo = valorNormal.getValorMaximo();
                if ( (minimo != null && valor < minimo) || (maximo != null && valor > maximo) ) {
                    return "background:red";
                }
            }
        }
        return null;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 89 * hash + Objects.hashCode(this.id);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ResultadoComponente other = (ResultadoComponente) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }
    
    @Override
    public String toString() {
        return "Cambiar toString ResultadoComponente";
    }
}
